<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html>
<html>
<head>
    <title>用户维护</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/lib/weui.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/css/jquery-weui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/css/main.css">

</head>

<body ontouchstart>


<header class='demos-header'>
    <h1 class="demos-title">${action=='add'?"添加":"编辑"}用户</h1>
</header>
<form id="form" action="${pageContext.request.contextPath}/apply/saveApply.do" method="post">
    <div class="weui-cells weui-cells_form">

        <input type="hidden" name="id" value="${addUser.id}">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="name" id="name" placeholder="请输入姓名" value="${addUser.name}">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">用户名</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="userName" id="username" value="${addUser.userName}"
                       placeholder="请输入用户名">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">密码</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="password" id="password" value="${addUser.password}"
                       placeholder="请输入密码">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label for="deptCode" class="weui-label">单位</label>
            </div>
            <div class="weui-cell__bd">
                <select class="weui-select" name="deptCode" id="deptCode" value="${addUser.deptCode}">
                    <option value="">==请选择单位==</option>
                    <c:forEach items="${deptList}" var="dept">
                        <option <c:if test="${dept.deptCode==addUser.deptCode}">selected</c:if> value="${dept.deptCode}">${dept.deptName}</option>
                    </c:forEach>
                </select>
            </div>
        </div>

        <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label for="role" class="weui-label">职务</label>
                </div>
                <div class="weui-cell__bd">
                    <select class="weui-select" name="role" id="role">
                        <option value="">==请选择职务==</option>
                        <c:forEach items="${roleList}" var="role">
                        <option <c:if test="${role.key==addUser.role}">selected</c:if> value="${role.key}" >${role.key}</option>
                        </c:forEach>
                    </select>
                </div>
        </div>

        <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">手机号</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="tel" name="phone" id="phone" value="${user.phone}"
                           placeholder="请输入手机号">
                </div>
        </div>
    </div>
</form>

<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="showTooltips">确定</a>
</div>
<div class="weui-tabbar">
    <a href="${pageContext.request.contextPath}/index.do" class="weui-tabbar__item weui-bar__item">
        <div class="weui-tabbar__icon">
            <img src="${pageContext.request.contextPath}/static/weui/images/index.png" alt="">
        </div>
        <p class="weui-tabbar__label">返回首页</p>
    </a>
</div>
<script src="${pageContext.request.contextPath}/static/weui/lib/jquery-2.1.4.js"></script>
<script src="${pageContext.request.contextPath}/static/weui/lib/fastclick.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script src="${pageContext.request.contextPath}/static/weui/js/jquery-weui.js"></script>


<script>
    $("#showTooltips").click(function () {
        var tel = $('#phone').val();
        var name = $("#name").val();
        var role = $("#role").val();
        var dept = $("#deptCode").val();
        var username = $("#username");
        var password = $("#password");
        if (!name) {
            $.toptip('请输入姓名');
        } else if (!username) {
            $.toptip('请输入用户名');
        } else if (!password) {
            $.toptip('请输入密码');
        } else if (!role) {
            $.toptip('请选择职务');
        } else if (!dept) {
            $.toptip('请选择部门');
        } else if (!tel || !/1[3|4|5|7|8]\d{9}/.test(tel)) {
            $.toptip('请输入手机号');
        } else {
            $.ajax({
                url: '${pageContext.request.contextPath}/user/savaUser.do',
                data: $("#form").serialize(),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.code == '200') {
                        window.location = "${pageContext.request.contextPath}/index.do";
                    } else {
                        $.alert(data.msg, "失败");
                    }

                }
            });
        }
    });
</script>
</body>
</html>
